/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.26                          *
*        Compiled Aug  8 2014, 14:49:54                              *
*        (c) 2013 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/


#include "DIALOG.h"
#include "DLG.h"
#include "bh1750.h"
#include "MQ135_ADC.h"
#include "dht11.h"
#include <stdio.h>
#include <os.h>

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/


#define ID_FRAMEWIN_0        (GUI_ID_USER + 0x00)
#define ID_TEXT_0        (GUI_ID_USER + 0x09)
#define ID_TEXT_1        (GUI_ID_USER + 0x0A)
#define ID_TEXT_2        (GUI_ID_USER + 0x0B)
#define ID_BUTTON_0        (GUI_ID_USER + 0x04)
#define ID_TEXT_3        (GUI_ID_USER + 0x05)
#define ID_TEXT_4        (GUI_ID_USER + 0x0C)
#define ID_IMAGE_0        (GUI_ID_USER + 0x06)
#define ID_IMAGE_1 (GUI_ID_USER + 0x07)
#define ID_IMAGE_2 (GUI_ID_USER + 0x08)
#define ID_IMAGE_3 (GUI_ID_USER + 0x0E)


extern GUI_BITMAP bmwenduji_icon;
extern GUI_BITMAP bmguangzhao_icon;
extern GUI_BITMAP bmranqi_icon;
extern GUI_BITMAP bmshidu_icon;
extern GUI_FONT GUI_Fontjujia24;
extern GUI_FONT GUI_FontMVBoli64;
extern GUI_FONT GUI_Fontshuju_anniu40;


int tempdata[4]; 

char temp_data[5];
char humi_data[5];
char lux_data[15];
char mq_data[5];
// USER START (Optionally insert additional defines)
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 800, 480, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_0, 96, 42, 270, 100, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_1, 92, 180, 270, 100, 0, 0x64, 0 },//光照数值
  { TEXT_CreateIndirect, "Text", ID_TEXT_2, 512, 180, 270, 100, 0, 0x64, 0 },  //燃气数值
	{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 500, 303, 258, 150, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_3, 512, 43, 270, 100, 0, 0x0, 0 },//湿度数值
	{ IMAGE_CreateIndirect, "Image", ID_IMAGE_0, 17, 50, 128, 128, 0, 0, 0 },  
  { IMAGE_CreateIndirect, "Image", ID_IMAGE_1, 17, 180, 128, 128, 0, 0, 0 },//光照
  { IMAGE_CreateIndirect, "Image", ID_IMAGE_2, 400, 180, 128, 128, 0, 0, 0 },//燃气
  { IMAGE_CreateIndirect, "Image", ID_IMAGE_3, 400, 50, 128, 128, 0, 0, 0 },//湿度
	{TEXT_CreateIndirect, "Text", ID_TEXT_4, 0, 0, 795, 35, 0, 0x0, 0 },

};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)
// USER END

/*********************************************************************
*
*       _cbDialog
*/

WM_HWIN hWin_temp_Edit;
WM_HWIN hWin_humi_Edit;
WM_HWIN hWin_lux_Edit;
WM_HWIN hWin_ppm_Edit;
u8 windos_flag;
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
	int     NCode;
  int     Id;
	
  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
		
		/* 数据更新标志位置位 */
		windos_flag = 1;
		//printf("windos_flag : %d\r\n",windos_flag);
	
		/*****************************************************************************************
																					样式设置
		*****************************************************************************************/
	
		GUI_UC_SetEncodeUTF8();
		hItem = pMsg->hWin;	
		FRAMEWIN_SetTitleVis(hItem,0);
	
		hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_4);
    TEXT_SetFont(hItem, &GUI_Fontjujia24);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		TEXT_SetText(hItem,"居家数据");
		TEXT_SetBkColor(hItem,0x000000);
		TEXT_SetTextColor(hItem,0xffffff);
	
	
		hWin_temp_Edit = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
		hWin_humi_Edit = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
		hWin_lux_Edit = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
		hWin_ppm_Edit = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
	
    hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_0);
    IMAGE_SetBitmap(hItem,&bmwenduji_icon);
		hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_1);
    IMAGE_SetBitmap(hItem,&bmguangzhao_icon);
		hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_2);
    IMAGE_SetBitmap(hItem,&bmranqi_icon);
		hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_3);
    IMAGE_SetBitmap(hItem,&bmshidu_icon);
	
		hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetFont(hItem, &GUI_FontMVBoli64);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0),"loading");
    TEXT_SetTextColor(hItem, 0x00000000);
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
    TEXT_SetText(hItem, "Text");
    TEXT_SetFont(hItem, &GUI_FontMVBoli64);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_1),"loading");
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
    TEXT_SetText(hItem, "Text");
    TEXT_SetFont(hItem, &GUI_FontMVBoli64);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_2),"loading");
		
		hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
    TEXT_SetFont(hItem, &GUI_FontMVBoli64);
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
		TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_3),"loading");
		hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetFont(hItem, &GUI_Fontshuju_anniu40);
    BUTTON_SetText(hItem, "返回");
		
		break;
		/*****************************************************************************************
		*****************************************************************************************/
		
	case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id){
    case ID_BUTTON_0: // Notifications sent by 'Button'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        break;
      case WM_NOTIFICATION_RELEASED:
					windos_flag = 0;
					GUI_EndDialog(pMsg->hWin,0);
					CreateFramewin();
        break;
      }
		break;
    }
		break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateFramewin
*/
WM_HWIN CreateDataUi(void);
WM_HWIN CreateDataUi(void) {
  WM_HWIN hWin;
	WM_SetCreateFlags(WM_CF_MEMDEV_ON_REDRAW); 
	hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
	return hWin;
}


// USER START (Optionally insert additional public code)
// USER END

/*************************** End of file ****************************/
